from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-04 16:28:53.214585
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 04, Jan, 2021
Time: 16:28:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.5656
Nobs: 161.000 HQIC: -45.5887
Log likelihood: 1760.15 FPE: 7.90583e-21
AIC: -46.2881 Det(Omega_mle): 4.59638e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458325 0.156964 2.920 0.004
L1.Burgenland 0.137247 0.079762 1.721 0.085
L1.Kärnten -0.236036 0.064274 -3.672 0.000
L1.Niederösterreich 0.111934 0.186054 0.602 0.547
L1.Oberösterreich 0.253465 0.159124 1.593 0.111
L1.Salzburg 0.173907 0.082222 2.115 0.034
L1.Steiermark 0.081254 0.114517 0.710 0.478
L1.Tirol 0.148845 0.076460 1.947 0.052
L1.Vorarlberg 0.007435 0.073127 0.102 0.919
L1.Wien -0.119575 0.154004 -0.776 0.437
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512571 0.202909 2.526 0.012
L1.Burgenland 0.012305 0.103109 0.119 0.905
L1.Kärnten 0.367186 0.083088 4.419 0.000
L1.Niederösterreich 0.137773 0.240514 0.573 0.567
L1.Oberösterreich -0.187045 0.205702 -0.909 0.363
L1.Salzburg 0.186019 0.106290 1.750 0.080
L1.Steiermark 0.249858 0.148038 1.688 0.091
L1.Tirol 0.141801 0.098840 1.435 0.151
L1.Vorarlberg 0.178509 0.094532 1.888 0.059
L1.Wien -0.583507 0.199083 -2.931 0.003
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295452 0.068394 4.320 0.000
L1.Burgenland 0.105454 0.034755 3.034 0.002
L1.Kärnten -0.026364 0.028006 -0.941 0.347
L1.Niederösterreich 0.068314 0.081070 0.843 0.399
L1.Oberösterreich 0.290045 0.069335 4.183 0.000
L1.Salzburg -0.001126 0.035827 -0.031 0.975
L1.Steiermark -0.020859 0.049899 -0.418 0.676
L1.Tirol 0.089511 0.033316 2.687 0.007
L1.Vorarlberg 0.126243 0.031864 3.962 0.000
L1.Wien 0.079952 0.067104 1.191 0.233
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203712 0.079157 2.574 0.010
L1.Burgenland -0.012239 0.040224 -0.304 0.761
L1.Kärnten 0.022528 0.032413 0.695 0.487
L1.Niederösterreich 0.027870 0.093827 0.297 0.766
L1.Oberösterreich 0.412473 0.080246 5.140 0.000
L1.Salzburg 0.096345 0.041465 2.324 0.020
L1.Steiermark 0.181790 0.057751 3.148 0.002
L1.Tirol 0.032634 0.038558 0.846 0.397
L1.Vorarlberg 0.096236 0.036878 2.610 0.009
L1.Wien -0.062815 0.077664 -0.809 0.419
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.592546 0.165175 3.587 0.000
L1.Burgenland 0.074192 0.083934 0.884 0.377
L1.Kärnten 0.002872 0.067636 0.042 0.966
L1.Niederösterreich -0.035736 0.195786 -0.183 0.855
L1.Oberösterreich 0.155257 0.167448 0.927 0.354
L1.Salzburg 0.051621 0.086523 0.597 0.551
L1.Steiermark 0.110962 0.120508 0.921 0.357
L1.Tirol 0.209074 0.080459 2.599 0.009
L1.Vorarlberg 0.005686 0.076952 0.074 0.941
L1.Wien -0.148745 0.162060 -0.918 0.359
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159152 0.114905 1.385 0.166
L1.Burgenland -0.025756 0.058390 -0.441 0.659
L1.Kärnten -0.013306 0.047052 -0.283 0.777
L1.Niederösterreich 0.177546 0.136201 1.304 0.192
L1.Oberösterreich 0.393332 0.116487 3.377 0.001
L1.Salzburg -0.027973 0.060191 -0.465 0.642
L1.Steiermark -0.046687 0.083832 -0.557 0.578
L1.Tirol 0.189857 0.055972 3.392 0.001
L1.Vorarlberg 0.039783 0.053532 0.743 0.457
L1.Wien 0.162376 0.112739 1.440 0.150
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236648 0.145980 1.621 0.105
L1.Burgenland 0.065618 0.074180 0.885 0.376
L1.Kärnten -0.048380 0.059776 -0.809 0.418
L1.Niederösterreich -0.017099 0.173034 -0.099 0.921
L1.Oberösterreich -0.104898 0.147989 -0.709 0.478
L1.Salzburg 0.006534 0.076469 0.085 0.932
L1.Steiermark 0.374192 0.106503 3.513 0.000
L1.Tirol 0.514066 0.071109 7.229 0.000
L1.Vorarlberg 0.199229 0.068010 2.929 0.003
L1.Wien -0.222992 0.143227 -1.557 0.119
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121853 0.168957 0.721 0.471
L1.Burgenland 0.014758 0.085857 0.172 0.864
L1.Kärnten -0.114077 0.069185 -1.649 0.099
L1.Niederösterreich 0.215140 0.200270 1.074 0.283
L1.Oberösterreich 0.011476 0.171283 0.067 0.947
L1.Salzburg 0.222274 0.088505 2.511 0.012
L1.Steiermark 0.144123 0.123267 1.169 0.242
L1.Tirol 0.093419 0.082302 1.135 0.256
L1.Vorarlberg 0.013972 0.078714 0.178 0.859
L1.Wien 0.288165 0.165771 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.586168 0.093073 6.298 0.000
L1.Burgenland -0.020693 0.047295 -0.438 0.662
L1.Kärnten 0.000162 0.038112 0.004 0.997
L1.Niederösterreich -0.007419 0.110322 -0.067 0.946
L1.Oberösterreich 0.281380 0.094354 2.982 0.003
L1.Salzburg 0.010355 0.048754 0.212 0.832
L1.Steiermark -0.000964 0.067904 -0.014 0.989
L1.Tirol 0.075699 0.045337 1.670 0.095
L1.Vorarlberg 0.170481 0.043361 3.932 0.000
L1.Wien -0.090560 0.091318 -0.992 0.321
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.139699 -0.004128 0.205731 0.243771 0.059222 0.100588 -0.084178 0.161854
Kärnten 0.139699 1.000000 -0.007160 0.186476 0.131259 -0.145124 0.174459 0.030271 0.298227
Niederösterreich -0.004128 -0.007160 1.000000 0.260858 0.077097 0.201822 0.097065 0.042882 0.350476
Oberösterreich 0.205731 0.186476 0.260858 1.000000 0.276864 0.291792 0.109723 0.074915 0.109594
Salzburg 0.243771 0.131259 0.077097 0.276864 1.000000 0.146872 0.078526 0.079477 -0.019171
Steiermark 0.059222 -0.145124 0.201822 0.291792 0.146872 1.000000 0.104547 0.086495 -0.129724
Tirol 0.100588 0.174459 0.097065 0.109723 0.078526 0.104547 1.000000 0.143036 0.147012
Vorarlberg -0.084178 0.030271 0.042882 0.074915 0.079477 0.086495 0.143036 1.000000 0.101122
Wien 0.161854 0.298227 0.350476 0.109594 -0.019171 -0.129724 0.147012 0.101122 1.000000